package com.yyn.client2.dao;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;

public class WriterThread extends Thread {
    private String name;
    private SocketChannel socketChannel;
    private String toName;

    public WriterThread(String name, SocketChannel socketChannel,String toName) {
        this.name = name;
        this.socketChannel = socketChannel;
        this.toName=toName;
    }

    @Override
    public void run() {
        while (true) {
            System.out.println("请输入：");
            Scanner scanner = new Scanner(System.in);
            String s = scanner.next();
            try {
                socketChannel.write(ByteBuffer.wrap((name + ":" + s+":"+toName).getBytes(StandardCharsets.UTF_8)));
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
